package com.glory.wxelectricitypda.utils;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;

public class FreeApi_EditTextUtils {
    public FreeApi_EditTextUtils() {
    }

    public static void setEditTextListener(EditText editText, final Context context, final FreeUI_TextCallback callback) {
        editText.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    if (s.length() > 0) {
                        callback.onSuccess(s.toString());
                    } else {
                        FreeApi_ToastUtils.showFreeToast("扫描信息有误", context, false, 1);
                    }
                }

            }

            public void afterTextChanged(Editable s) {
            }
        });
    }
}
